<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bai 3.5</title>
</head>

<body>
<?php
	function TongMang($arr)
	{
		$tong=0;
		for($i=0;$i<count($arr);$i++)
		{
			$tong+=$arr[$i];
		}
		return $tong;
	}
	function TaoMang($n)
	{
		for($i=0;$i<$n;$i++)
			$arr[$i]=rand(0,20);
		return $arr;
	}
	function XuatMang($arr)
	{
			for($i=0;$i<count($arr);$i++)
				$mang.=$arr[$i]." ";
			return $mang;
	}
	if(isset($_POST['sopt']))
	{
		$n=$_POST['sopt'];
		$arr=TaoMang($n);
		$mang=XuatMang($arr);
		$max=max($arr);
		$min=min($arr);
		$tong=TongMang($arr);
	}
?>
<form id="form1" name="form1" method="post" action="Bai3_5.php">
  <table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr bgcolor="#990066" style="text-align: center; font-size: 24px; font-weight: bold; font-style: italic; color: #FFF;">
      <td colspan="2">PHÁT SINH MẢNG TÍNH TOÁN</td>
    </tr>
    <tr>
      <td nowrap="nowrap" bgcolor="#FF99FF">Nhập số phần tử:</td>
      <td nowrap="nowrap" bgcolor="#FF99FF"><input name="sopt" type="text" id="sopt" value="<?php echo $_POST['sopt'];?>" /></td>
    </tr>
    <tr>
      <td nowrap="nowrap" bgcolor="#FF99FF">&nbsp;</td>
      <td nowrap="nowrap" bgcolor="#FF99FF"><input style="background-color:#FFC" type="submit" name="button" id="button" value="Phát sinh và tính toán" /></td>
    </tr>
    <tr>
      <td nowrap="nowrap" bgcolor="#FFCCFF">Mảng:</td>
      <td nowrap="nowrap" bgcolor="#FFCCFF"><input name="mang" type="text" id="mang" style="background-color:#C33" value="<?php echo $mang;?>" size="96%" /></td>
    </tr>
    <tr>
      <td nowrap="nowrap" bgcolor="#FFCCFF">GTLN (MAX) trong mảng:</td>
      <td nowrap="nowrap" bgcolor="#FFCCFF"><input name="max" type="text" disabled="disabled" id="max" style="background-color:#C33" value="<?php echo $max;?>" /></td>
    </tr>
    <tr>
      <td nowrap="nowrap" bgcolor="#FFCCFF">GTNN (MIN) trong mảng:</td>
      <td nowrap="nowrap" bgcolor="#FFCCFF"><input name="min" type="text" disabled="disabled" id="min" style="background-color:#C33" value="<?php echo $min;?>" /></td>
    </tr>
    <tr>
      <td nowrap="nowrap" bgcolor="#FFCCFF">Tổng mảng:</td>
      <td nowrap="nowrap" bgcolor="#FFCCFF"><input name="tong" type="text" disabled="disabled" id="tong" style="background-color:#C33" value="<?php echo $tong;?>" /></td>
    </tr>
    <tr>
      <td colspan="2" bgcolor="#FFCCFF">(<span style="color: #C00; font-weight: bold;">Ghi chú</span>: Các phần tử trong mảng sẽ có giá trị từ 0 đến 20)</td>
    </tr>
  </table>
</form>
</body>
</html>